//
//  ApplyInfo.m
//  HxgProject
//
//  Created by XMYY-19 on 2018/4/3.
//  Copyright © 2018年 XMYY-19. All rights reserved.
//

#import "ApplyInfo.h"

@implementation ApplyInfo


-(instancetype)init
{
    self = [super init];
    if (self)
    {
        self.applyCycle = @"无";
        self.applyTime = @"2018-04-06 02:47:18";
        self.curState = @"无";
        self.applyNum = @"0";
    }
    return self;
}

- (instancetype)initWithDic:(NSDictionary *)dic;
{
    if ([self init]) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
    if ([key isEqualToString:@"loanPackage"]) {
        self.applyNum = value;
    }
   
    if ([key isEqualToString:@"loanperiod"]) {
        self.applyCycle = value;
    }
    
    if ([key isEqualToString:@"children"]) {
        self.curState = [self getCurStateWith:value];
    }
    
    
    
}

- (NSString *)getCurStateWith:(NSArray *)childArr {
    
    int loanOperationInt = -1;
    NSDictionary *tempDic = nil;
    for (NSDictionary *dic in childArr) {

        int tempLoanOperation = 0;
        if (!isEmptyString(dic[@"loanOperation"])) {
            tempLoanOperation = [dic[@"loanOperation"] intValue];
        }

        if (tempLoanOperation > loanOperationInt) {
            loanOperationInt = tempLoanOperation;
            tempDic   = dic;
        }
    }
    
    return [self getRepaymentStatusStr:tempDic[@"loanOperation"]];
}


- (NSString *)getRepaymentStatusStr:(NSString *)loanOperationStr {
    NSString *stateStr = @"待审核";
    if ([loanOperationStr isEqualToString:@"4"]) {
        stateStr = @"已逾期";
    } else if ([loanOperationStr isEqualToString:@"3"]) {
        stateStr = @"已结束";
    }else if ([loanOperationStr isEqualToString:@"2"]) {
        stateStr = @"已通过";
    } else if ([loanOperationStr isEqualToString:@"1"]) {
        stateStr = @"待审核";
    }
    
    return stateStr;
}

@end
